import java.util.Scanner;

/**
 * 字符串排序
 */
public class HJ14 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            //输入
            String numStr = sc.nextLine();
            int num = Integer.parseInt(numStr);
            String[] strArrays = new String[num];
            for (int i = 0; i < num; i++) {
                strArrays[i] = sc.nextLine();
            }

            //排序
            String strTemp = "";
            for (int i = 0; i < num; i++) {
                for (int j = i + 1; j < num; j++) {
                    if (exchange(strArrays[i], strArrays[j])) {
                        strTemp = strArrays[i];
                        strArrays[i] = strArrays[j];
                        strArrays[j] = strTemp;
                    }
                }
            }

            //输出
            for (String strArray : strArrays) {
                System.out.println(strArray);
            }
        }
    }

    private static boolean exchange(String strA, String strB) {
        for (int i = 0; i < Math.min(strA.length(), strB.length()); i++) {
            if (strA.charAt(i) > strB.charAt(i)) {
                return true;
            } else if (strA.charAt(i) < strB.charAt(i)){
                return false;
            }
        }
        if (strA.length() >= strB.length()) {
            return true;
        } else {
            return false;
        }
    }
}
